package com.shangma.cn.interceptor;

import com.shangma.cn.components.TokenService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 开发者：辉哥
 * 特点： 辉哥很帅
 * 开发时间：2021/7/1 17:04
 * 文件说明：
 */
@Component
public class LoginInterceptor implements HandlerInterceptor {

    @Autowired
    private TokenService tokenService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //判断用户是否登录
        //从头部中取出 token
        //判断token是否准确
        // 1: 前缀是不是Bearer开头
        // 2: 能不能解析成功
        return tokenService.checkTokenIsSure(request);
    }
}
